package com.ruoyi.insert.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.profession.domain.WorkExperience;
import com.ruoyi.profession.service.IWorkExperienceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 工作履历Controller
 * 
 * @author 靳双伟
 * @date 2024-06-02
 */
@RestController
@RequestMapping("/insert/workExperience")
public class IWorkExperienceController extends BaseController
{
    @Autowired
    private IWorkExperienceService workExperienceService;

    /**
     * 查询工作履历列表
     */
    @PreAuthorize("@ss.hasPermi('profession:workExperience:list')")
    @GetMapping("/list")
    public TableDataInfo list(WorkExperience workExperience)
    {
        startPage();
        List<WorkExperience> list = workExperienceService.selectWorkExperienceList(workExperience);
        return getDataTable(list);
    }

    /**
     * 导出工作履历列表
     */
    @PreAuthorize("@ss.hasPermi('profession:workExperience:export')")
    @Log(title = "工作履历", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, WorkExperience workExperience)
    {
        List<WorkExperience> list = workExperienceService.selectWorkExperienceList(workExperience);
        ExcelUtil<WorkExperience> util = new ExcelUtil<WorkExperience>(WorkExperience.class);
        util.exportExcel(response, list, "工作履历数据");
    }

    /**
     * 获取工作履历详细信息
     */
    @PreAuthorize("@ss.hasPermi('profession:workExperience:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(workExperienceService.selectWorkExperienceById(id));
    }

    /**
     * 新增工作履历
     */
    @PreAuthorize("@ss.hasPermi('profession:workExperience:add')")
    @Log(title = "工作履历", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody WorkExperience workExperience)
    {
        return toAjax(workExperienceService.insertWorkExperience(workExperience));
    }

    /**
     * 修改工作履历
     */
    @PreAuthorize("@ss.hasPermi('profession:workExperience:edit')")
    @Log(title = "工作履历", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody WorkExperience workExperience)
    {
        return toAjax(workExperienceService.updateWorkExperience(workExperience));
    }

    /**
     * 删除工作履历
     */
    @PreAuthorize("@ss.hasPermi('profession:workExperience:remove')")
    @Log(title = "工作履历", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(workExperienceService.deleteWorkExperienceByIds(ids));
    }
}
